import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;

import java.io.IOException;

/**
 * @Author penglai
 * @Date 2016/10/8.
 */
public class SolrjPopulator {
    public static void main(String[] args) throws IOException, SolrServerException {
        HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr");
        String urlString = "http://localhost:8983/solr/techproducts";
        SolrClient solr = new HttpSolrClient(urlString);
        for (int i = 0; i < 1000; ++i) {
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("cat", "book");
            doc.addField("id", "book-" + i);
            doc.addField("name", "The Legend of the Hobbit part " + i);
            server.add(doc);
            if (i % 100 == 0) server.commit();  // periodically flush
        }
        server.commit();


    }
}
